package org.ws.task.netty;


public class NettyConfig {

    private int serverPort;

    private int workerGroupThreadNum = 8;

    private int executorThreadNum = 8;

    private int connectTimeoutMillis = 10_000;

    // 处理请求并发线程数
    private int requestThreadPermitsCount = 64;

    private int idleTimeoutMillis = 10_000;

    public int getServerPort() {
        return serverPort;
    }

    public int getWorkerGroupThreadNum() {
        return workerGroupThreadNum;
    }

    public int getExecutorThreadNum() {
        return executorThreadNum;
    }

    public int getConnectTimeoutMillis() {
        return connectTimeoutMillis;
    }

    public int getRequestThreadPermitsCount() {
        return requestThreadPermitsCount;
    }

    public int getIdleTimeoutMillis() {
        return idleTimeoutMillis;
    }

    public void setServerPort(int serverPort) {
        this.serverPort = serverPort;
    }

    public void setWorkerGroupThreadNum(int workerGroupThreadNum) {
        this.workerGroupThreadNum = workerGroupThreadNum;
    }

    public void setExecutorThreadNum(int executorThreadNum) {
        this.executorThreadNum = executorThreadNum;
    }

    public void setConnectTimeoutMillis(int connectTimeoutMillis) {
        this.connectTimeoutMillis = connectTimeoutMillis;
    }

    public void setRequestThreadPermitsCount(int requestThreadPermitsCount) {
        this.requestThreadPermitsCount = requestThreadPermitsCount;
    }

    public void setIdleTimeoutMillis(int idleTimeoutMillis) {
        this.idleTimeoutMillis = idleTimeoutMillis;
    }

    public static NettyConfigBuilder builder(){
        return new NettyConfigBuilder();
    }


    public static final class NettyConfigBuilder {
        private int port;
        private int workerGroupThreadNum = 8;
        private int executorThreadNum = 8;
        private int connectTimeoutMillis = 10_000;
        // 处理请求并发线程数
        private int requestThreadPermitsCount = 64;
        private int idleTimeoutMillis = 10_000;

        private NettyConfigBuilder() {
        }

        public NettyConfigBuilder port(int port) {
            this.port = port;
            return this;
        }

        public NettyConfigBuilder workerGroupThreadNum(int workerGroupThreadNum) {
            this.workerGroupThreadNum = workerGroupThreadNum;
            return this;
        }

        public NettyConfigBuilder executorThreadNum(int executorThreadNum) {
            this.executorThreadNum = executorThreadNum;
            return this;
        }

        public NettyConfigBuilder connectTimeoutMillis(int connectTimeoutMillis) {
            this.connectTimeoutMillis = connectTimeoutMillis;
            return this;
        }

        public NettyConfigBuilder requestThreadPermitsCount(int requestThreadPermitsCount) {
            this.requestThreadPermitsCount = requestThreadPermitsCount;
            return this;
        }

        public NettyConfigBuilder idleTimeoutMillis(int idleTimeoutMillis) {
            this.idleTimeoutMillis = idleTimeoutMillis;
            return this;
        }

        public NettyConfig build() {
            NettyConfig nettyConfig = new NettyConfig();
            nettyConfig.idleTimeoutMillis = this.idleTimeoutMillis;
            nettyConfig.requestThreadPermitsCount = this.requestThreadPermitsCount;
            nettyConfig.serverPort = this.port;
            nettyConfig.executorThreadNum = this.executorThreadNum;
            nettyConfig.connectTimeoutMillis = this.connectTimeoutMillis;
            nettyConfig.workerGroupThreadNum = this.workerGroupThreadNum;
            return nettyConfig;
        }
    }
}
